<template>
  <div>
    <v-header v-if="seller" :seller="seller"></v-header>
    <div class="tab border-1px">
      <!-- 使用 router-link 组件来导航. -->
      <!-- 通过传入 `to` 属性指定链接. -->
      <!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->
      <div class="tab-item">
        <router-link to="/goods">商品</router-link>
      </div>
      <div class="tab-item">
        <router-link to="/ratings">评价</router-link>
      </div>
      <div class="tab-item">
        <router-link to="/seller">商家</router-link>
      </div>
    </div>
    <!-- 路由出口 -->
    <!-- 路由匹配到的组件将渲染在这里 -->
    <keep-alive>
      <router-view :seller="seller" ></router-view>
    </keep-alive>
  </div>
</template>

<script type="text/ecmascript-6">
  import header from './components/header/header.vue';

  //  errno: 0,
  const ERR_OK = 0;
  export default {
    //定义一个函数接受ajax传来的数据 再通过props传递给前端
    data() {
      return {
        //定义一个seller对象接受
        seller: {}
      }
    },
    created() {
      this.$nextTick(() => {
        this.$http.get('/api/seller').then((response) => {
          response = response.body;
          if (response.errno === ERR_OK) {
            //如果正确接受数据
            this.seller = response.data;
          }
        })
      });
      //获取vue-resource后台的数据  查看api
    },
    components: {
      'v-header': header
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "common/stylus/minix.styl"
  .tab
    display flex
    height 40px
    width: 100%
    line-height 40px
    border-1px(rgba(7, 17, 27, 0.1))
    .tab-item
      flex 1
      text-align center
      & > a
        display block
        color rgb(77, 85, 93)
        font-size 14px
        font-weight 700
        &.active
          color rgb(240, 20, 20)
</style>
